/* 
 * Copyright [2018] [Alex/libo(liboware@gmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.template.freemarker;

import java.io.IOException;

import com.hyts.scanner.utility.StringUtils;

import freemarker.template.Template;
import lombok.extern.slf4j.Slf4j;

/** 
 * @author LiBo/Alex
 * @version V1.0 
 */
@Slf4j
public class FreemarkerTemplate {


    /**
     * 
     * @param templateName
     * @return
     * @exception
     */
    @Deprecated
    static Template getTemplate(String templateName) {
        FreemarkerContext context = new FreemarkerContext();
        context.createContext();
        return getTemplate(templateName,context);
    }
    
    /**  
     * @param templateName
     * @param context
     * @return
     * @exception
     */ 
    static Template getTemplate(String templateName,FreemarkerContext context) {
        try {
            if(StringUtils.isBlank(templateName)) {
                throw new NullPointerException("传入的模板名称不可以为空！");
            }
            return context.getConfiguration().getTemplate(templateName);
        } catch (IOException e) {
            log.error("获取模板异常：",e);
        }
        return null;
    }
}
